package servlet.huwenyao;

import net.sf.json.JSONObject;
import service.OrderService;
import service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 批量删除订单
 */
@WebServlet(value = "/DeleteAllOrderServlet")
public class DeleteAllOrderServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/json;charset=UTF-8");
        OrderService os = new OrderServiceImpl();
        int i = 0;
        //接受参数
        String ids = request.getParameter("ids");
        if (null != ids && !"".equals(ids)) {
            for (String id : ids.split(",")) {
                i = os.deleOrder(Integer.parseInt(id));
            }
        }
        //创建json对象
        JSONObject json=new JSONObject();
        if (i > 0) {
            json.put("msg","删除成功!");
        } else {
            json.put("msg","删除失败!");
        }
        PrintWriter out = response.getWriter();
        out.print(json);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
